package com.gitee.kamismile.igniteEx.spring.binding;

import com.gitee.kamismile.igniteEx.common.IginteConfigProperties;
import com.gitee.kamismile.igniteEx.ignite.ServiceHandle;

import java.lang.reflect.Proxy;

public class MapperProxyFactory<T> {
    private final Class<T> mapperInterface;

    public MapperProxyFactory(Class<T> mapperInterface) {
        this.mapperInterface = mapperInterface;
    }

    public Class<T> getMapperInterface() {
        return mapperInterface;
    }

    protected T newInstance(MapperProxy<T> mapperProxy) {
        return (T) Proxy.newProxyInstance(mapperInterface.getClassLoader(), new Class[]{mapperInterface}, mapperProxy);
    }

    public T newInstance(ServiceHandle serviceHandle, IginteConfigProperties iginteConfigProperties) {
        final MapperProxy<T> mapperProxy = new MapperProxy<T>(mapperInterface, serviceHandle,iginteConfigProperties);
        return newInstance(mapperProxy);
    }
}
